home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / Bitmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  8.9 KB  |  270 lines

  1. /*
  2.  * (c) Copyright 1995, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  * Permission to use, copy, modify, and distribute this software for
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * US Government Users Restricted Rights
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * Author: John Spitzer, SGI Applied Engineering
  36.  *
  37.  */
  38. #include <math.h>
  39. #include "Bitmap.h"
  40. #include "BitmapX.h"
  41.  
  42. #undef offset
  43. #define offset(v) offsetof(Bitmap, v)
  44.  
  45. static InfoItem BitmapInfo[] = {
  46. #define INC_REASON INFO_ITEM_ARRAY
  47. #include "Bitmap.h"
  48. #undef INC_REASON
  49. };
  50. #include <malloc.h>
  51.  
  52. BitmapPtr new_Bitmap()
  53. {
  54.     BitmapPtr this = (BitmapPtr)malloc(sizeof(Bitmap));
  55.     ImagePtr thisImage = (ImagePtr)(&this->image_Bitmap);
  56.  
  57.     CheckMalloc(this);
  58.     new_RasterPos((RasterPosPtr)this);
  59.     new_Image(thisImage);
  60.     SetDefaults((TestPtr)this, BitmapInfo);
  61.     this->testType = BitmapTest;
  62.     this->subImage = False;
  63.     this->traversalData = 0;
  64.     this->subImageData = 0;
  65.     this->imageData = 0;
  66.     this->usecPixelPrint = " microseconds per pixel with Bitmap";
  67.     this->ratePixelPrint = " pixels per second with Bitmap";
  68.     this->usecPrint = " microseconds per Bitmap image";
  69.     this->ratePrint = " Bitmap images per second";
  70.     /* Set virtual functions */
  71.     this->SetState = Bitmap__SetState;
  72.     this->delete = delete_Bitmap;
  73.     this->Copy = Bitmap__Copy;
  74.     this->Initialize = Bitmap__Initialize;
  75.     this->Cleanup = Bitmap__Cleanup;
  76.     this->SetExecuteFunc = Bitmap__SetExecuteFunc;
  77.     this->PixelSize = Bitmap__Size;
  78.     this->TimesRun = Bitmap__TimesRun;
  79.     return this;
  80. }
  81.  
  82. void delete_Bitmap(TestPtr thisTest)
  83. {
  84.     BitmapPtr this = (BitmapPtr)thisTest;
  85.     ImagePtr thisImage = (ImagePtr)(&this->image_Bitmap);
  86.  
  87.     delete_Image(thisImage);
  88.     delete_RasterPos(thisTest);
  89. }
  90.  
  91. TestPtr Bitmap__Copy(TestPtr thisTest)
  92. {
  93.     BitmapPtr this = (BitmapPtr)thisTest;
  94.     BitmapPtr newBitmap = new_Bitmap();
  95.     FreeStrings((TestPtr)newBitmap);
  96.     *newBitmap = *this;
  97.     CopyStrings((TestPtr)newBitmap, (TestPtr)this);
  98.     return (TestPtr)newBitmap;
  99. }
  100.  
  101. void Bitmap__Initialize(TestPtr thisTest)
  102. {
  103.     BitmapPtr this = (BitmapPtr)thisTest;
  104.     int windowDim = min(this->environ.windowWidth, this->environ.windowHeight);
  105.     int windowArea = windowDim * windowDim;
  106.     GLint *intTraversalData;
  107.     GLint *srcPtr;
  108.     GLfloat *dstPtr;
  109.     int i;
  110.  
  111.     if (this->image_Bitmap.imageWidth > windowDim)
  112.     this->image_Bitmap.imageWidth = windowDim;
  113.     if (this->image_Bitmap.imageHeight > windowDim)
  114.     this->image_Bitmap.imageHeight = windowDim;
  115.  
  116.     /* Source image is imageWidth by imageHeight,
  117.      * The portion drawn by glBitmap is bitmapWidth by bitmapHeight */
  118.     if (this->bitmapWidth != -1) {
  119.     this->subImage = True;
  120.     } else {
  121.     this->bitmapWidth = this->image_Bitmap.imageWidth;
  122.     }
  123.     if (this->bitmapHeight != -1) {
  124.     this->subImage = True;
  125.     } else {
  126.     this->bitmapHeight = this->image_Bitmap.imageHeight;
  127.  
  128.     }
  129.  
  130.     /* Layout RasterPos coordinates */
  131.     this->numDrawn = 0;
  132.     intTraversalData = CreateSubImageData(windowDim, windowDim, 
  133.                           (float)this->bitmapWidth, 
  134.                           (float)this->bitmapHeight,
  135.                           this->acceptObjs, this->rejectObjs, this->clipObjs,
  136.                           this->clipMode, this->clipAmount, this->drawOrder==Spaced, 
  137.                           this->memAlignment, &this->numDrawn);
  138.  
  139.     /* Convert RasterPos coordinates to NDC */
  140.     this->traversalData = (GLfloat*)AlignMalloc(sizeof(GLfloat) * this->rasterPosDim * this->numDrawn, this->memAlignment);
  141.     srcPtr = intTraversalData;
  142.     dstPtr = this->traversalData;
  143.     for (i = 0; i < this->numDrawn; i++) {
  144.         *dstPtr++ = ((double)(*srcPtr++) + .375) / (double)windowDim * 2. - 1.;
  145.         *dstPtr++ = ((double)(*srcPtr++) + .375) / (double)windowDim * 2. - 1.;
  146.  
  147.     }
  148.     AlignFree(intTraversalData);
  149.  
  150.     /* Add color and z coordinate if necessary */
  151.     RasterPos__AddTraversalData((RasterPosPtr)this);
  152.  
  153.     Bitmap__CreateImageData(this);
  154.  
  155.     /* Layout offsets in source image for subimage draws.
  156.      * All the subimages should lie entirely within the source image, so 100% of 
  157.      * our offsets should be "accepted".  numDrawn taken from RasterPos layout above.
  158.      */
  159.     if (this->subImage) {
  160.     this->subImageData = CreateSubImageData(this->image_Bitmap.imageWidth, 
  161.                                  this->image_Bitmap.imageHeight,
  162.                  this->bitmapWidth,
  163.                  this->bitmapHeight,
  164.                                  1., 0., 0., Random, 0., this->drawOrder==Spaced,
  165.                                  this->memAlignment, &this->numDrawn);
  166.     }
  167. }
  168.  
  169. void Bitmap__Cleanup(TestPtr thisTest)
  170. {
  171.     BitmapPtr this = (BitmapPtr)thisTest;
  172.     int i;
  173.  
  174.     if (this->traversalData) AlignFree(this->traversalData);
  175.     if (this->subImageData) AlignFree(this->subImageData);
  176.     if (this->imageData) {
  177.     void **imageDataPtr = this->imageData;
  178.         for (i = 0; i < this->numObjects; i++) AlignFree(*imageDataPtr++);
  179.     free(this->imageData);
  180.     }
  181. }
  182.  
  183. int Bitmap__SetState(TestPtr thisTest)
  184. {
  185.     BitmapPtr this = (BitmapPtr)thisTest;
  186.     ImagePtr thisImage = (ImagePtr)(&this->image_Bitmap);
  187.  
  188.     /* set parent state */
  189.     if (RasterPos__SetState(thisTest) == -1) return -1;
  190.  
  191.     /* set other inherited classes' states */
  192.     if (Image__SetState(thisImage) == -1) return -1;
  193.  
  194.     /* set own state */
  195.  
  196.     return 0;
  197. }
  198.  
  199. void Bitmap__SetExecuteFunc(TestPtr thisTest)
  200. {
  201.     BitmapPtr this = (BitmapPtr)thisTest;
  202.     BitmapFunc function;
  203.  
  204.     function.word = 0;
  205.  
  206.     function.bits.functionPtrs = this->loopFuncPtrs;
  207.     function.bits.subimage = this->subImage;
  208.     function.bits.multiimage = (this->numObjects > 1);
  209.     function.bits.colorData = (this->colorData == PerRasterPos) ? PER_RASTERPOS : NONE;
  210.     function.bits.visual = this->environ.bufConfig.rgba ? RGB : CI;
  211.  
  212.     /* Dimensions of data to be traversed */
  213.     function.bits.rasterPosDim  = this->rasterPosDim - 2;
  214.     function.bits.colorDim = this->colorDim - 3;
  215.  
  216.     this->Execute = BitmapExecuteTable[function.word];
  217. }
  218.  
  219. int Bitmap__TimesRun(TestPtr thisTest)
  220. {
  221.     BitmapPtr this = (BitmapPtr)thisTest;
  222.     return this->numDrawn;
  223. }
  224.  
  225. float Bitmap__Size(TestPtr thisTest)
  226. {
  227.     BitmapPtr this = (BitmapPtr)thisTest;
  228.     int accept = this->acceptObjs * (float)(this->numDrawn);
  229.     int reject = this->rejectObjs * (float)(this->numDrawn);
  230.     int clip = this->clipObjs * (float)(this->numDrawn);
  231.     float size = (float)this->bitmapWidth * (float)this->bitmapHeight;
  232.     float acceptSize, clipSize;
  233.  
  234.     accept += this->numDrawn - accept - reject - clip;
  235.  
  236.     acceptSize = (float)accept * size;
  237.     clipSize = (float)clip * (1. - this->clipAmount) * size;
  238.  
  239.     return (acceptSize + clipSize)/(float)this->numDrawn;
  240. }
  241.  
  242. void Bitmap__CreateImageData(BitmapPtr this)
  243. {
  244.     int i;
  245.     void **imagePtr;
  246.     int imageSize;
  247.     void *image;
  248.  
  249.     this->imageData = (void**)malloc(sizeof(void*) * this->numObjects);
  250.     CheckMalloc(this->imageData);
  251.     imagePtr = this->imageData;
  252.     if (this->numObjects)
  253.     image = new_ImageData(
  254.                          this->image_Bitmap.imageWidth,
  255.              this->image_Bitmap.imageHeight,
  256.              GL_COLOR_INDEX,
  257.              GL_BITMAP,
  258.              this->image_Bitmap.imageAlignment,
  259.              this->image_Bitmap.imageSwapBytes,
  260.              this->image_Bitmap.imageLSBFirst,
  261.              this->memAlignment,
  262.              &imageSize);
  263.     *imagePtr++ = image;
  264.     for (i = 1; i < this->numObjects; i++) {
  265.     *imagePtr = AlignMalloc(imageSize, this->memAlignment);
  266.     memcpy(*imagePtr, image, imageSize);
  267.     imagePtr++;
  268.     }
  269. }
  270.